app.controller("taskController", function ($scope, $controller, $location, taskService,uploadService) {

    $controller("baseController", {$scope: $scope});

    //定义条件查询对象
    $scope.searchEntity = {"taskBatchNo": null};

    //获取打款记录列表
    $scope.findPage = function (pageNum, pageSize) {

        if (pageNum == null) pageNum = 1;

        if (pageSize == null) pageSize = 10;

        if (startTime != null) {
            $scope.searchEntity.startTime = new Date(Date.parse(startTime.replace(/-/g, "/")));
        }

        if (endTime != null) {
            $scope.searchEntity.endTime = new Date(Date.parse(endTime.replace(/-/g, "/")));
        }

        taskService.findPage(pageNum, pageSize, $scope.searchEntity).success(function (response) {

            if (response.code == 200) {
                $scope.taskList = response.data;

                //更新总记录数
                $scope.paginationConf.totalItems = response.total;

            } else {
                alert(response.msg);
            }
        });

    };

    //重置条件查询参数
    $scope.resetSearchEntity = function () {

        $scope.searchEntity = {"taskBatchNo": null};

        $scope.reloadList();
    };

    //根据批次号查询订单明细
    $scope.findOneByBatchNumber = function () {

        //获取地址栏批次号
        var taskBatchNo = $location.search()['taskBatchNo'];

        if (taskBatchNo == null)
            return;
        //批次号
        $scope.searchEntity.taskBatchNo = taskBatchNo;


    };

    //监控订单状态变量
    $scope.$watch("searchEntity.taskBatchStatus", function (newValue, oldValue) {

        if (newValue == null) return;

        $scope.reloadList();
    });

    //数字四舍五入 num-数字 digit-保留位数
    $scope.numParse = function (num, digit) {

        var s = num.toFixed(digit);

        return s;
    };

    $scope.uploadParam = {"confirmLetter": null, "taskId": null};

    $scope.prompt = "请上传";

    //上传任务确认函
    $scope.uploadConfirmLetter = function () {
        console.log("上传执行")

        uploadService.uploadConfirmLetter_two().success(function (response) {

            if (response.code == 200) {

                $scope.uploadParam.confirmLetter = response.data;

                $scope.prompt = response.msg;

            } else {
                alert(response.msg);
            }

        });

    };

    //上传任务确认函时添加任务批次号
    $scope.addTaskId = function (taskId) {
        console.log("添加参数执行")
        $scope.uploadParam.taskId = taskId;
    };

    //添加确认函
    $scope.addConfirmLetter = function () {
        $scope.prompt = "请上传";
        if ($scope.isNull($scope.uploadParam.confirmLetter)) {
            alert("未上传确认函");
            return;
        }

        taskService.addConfirmLetter($scope.uploadParam).success(function (response) {

            if (response.code == 200) {

                $scope.reloadList();

            } else {

                alert(response.msg);
            }
        });

    };
});